<?php

namespace App\Admin\Controllers;

use App\Http\Controllers\Controller;
use App\Model\AppChannel;
use App\Model\AppVersion;
use App\Model\SettingAppHidden;
use App\Model\VideoCallAuditConfig;
use Encore\Admin\Controllers\ModelForm;
use Encore\Admin\Grid;
use Encore\Admin\Form;
use Encore\Admin\Layout\Content;

class VideoCallAuditConfigController extends Controller
{
    use ModelForm;

    public function index()
    {
        $content = new Content();
        $content->header('视频通话鉴黄配置');
        $content->body($this->grid());
        return $content;
    }

    public function edit($id)
    {
        $content = new Content();
        $content->header('编辑');
        $content->body($this->form()->edit($id));
        return $content;
    }

    public function create()
    {
        $content = new Content();
        $content->header('创建');
        $content->body($this->form());
        return $content;
    }

    protected function grid()
    {
        $grid = new Grid(new VideoCallAuditConfig());
        $grid->model()->orderBy('id', 'desc');
        $grid->begin_time('审核时间范围')->display(function ($data){
            return $data.'--'.$this->end_time;
        });
        $grid->version('鉴黄版本');
        $grid->channel('鉴黄渠道');
        $grid->frequency('截帧频率')->display(function ($data){
            return empty($data) ? '全部' :  $data;
        });
        $grid->flag('状态')->display(function ($data) {
            return $data == 1 ? '有效' : '无效';
        });

        //禁用导出
        $grid->disableExport();
        //禁用行选择
        $grid->disableRowSelector();
        $grid->disableFilter();
        $grid->actions(function (Grid\Displayers\Actions $actions) {
            // $actions->disableDelete();
            $actions->disableView();
        });
        return $grid;
    }

    protected function form()
    {
        $form = new Form(new VideoCallAuditConfig());
        $form->number('frequency', '截帧频率')->default(3)->required()->max(60)->min(1);
        $form->select('version', '版本')->options(AppVersion::getAllVersions())->default(-1);
        $form->multipleSelect('channel', '鉴黄渠道')->options(AppChannel::getChannels())->required();
        $form->select('flag', '是否有效')->options([1 => '有效', 0 => '无效'])->default(1)->required();
        $form->date('begin_time','开始时间')->format('HH:ss')->default('00:00');
        $form->date('end_time','开始时间')->format('HH:ss')->default('23:59');
        return $form;
    }
}
